package com.woniuxy01;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 作者
 * @create 2025-11-11 11:09
 */
public class Test05 {
    public static void main(String[] args)  {
        System.out.println(stringToDate03("aaa"));
        System.out.println("程序结束");
        stringToDate02("xxx");
    }

    private static Date stringToDate03(String str) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(str);
            return date;
        } catch (ParseException e) {
            //用户调用这个方法，能转换就转换，转不了，抛异常；没有必要返回默认值
            return new Date();
        }
    }


    private static Date stringToDate02(String str) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(str);
            return date;
        } catch (ParseException e) {
            //将受查异常转成非受查异常
            throw new RuntimeException(e);
        }
    }

    private static Date stringToDate01(String str) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(str);
        return date;
    }

}
